package com.google.code.sip.ucenter.ws.adapter;

import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang.StringUtils;

public class DateAdapter extends XmlAdapter<String, Date> {
	@Override
	public String marshal(Date v) throws Exception {
		return String.valueOf(v.getTime());
	}

	@Override
	public Date unmarshal(String v) throws Exception {
		if (StringUtils.isNumeric(v)) {
			return new Date(Long.parseLong(v));
		}
		return (Date) ConvertUtils.convert(v, Date.class);
	}
}
